package com.heima.search.controller;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.search.dtos.HistorySearchDto;
import com.heima.search.service.HistorySearchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author xiaquanen
 * @version 1.0
 * @project heima-leadnews
 * @date 2024/7/30 14:09:27
 */
@RestController
@Slf4j
@RequestMapping("/api/v1/history")
public class HistoryController {

    @Autowired
    private HistorySearchService historySearchService;


    /**
     * 查询搜索记录
     *
     * @return
     */
    @PostMapping("/load")
    public ResponseResult load() {
        log.info("收到前端请求了");
        return historySearchService.load();
    }

    /**
     * 删除搜索记录
     *
     * @param historySearchDto
     * @return
     */
    @PostMapping("/del")
    public ResponseResult deleteHistory(@RequestBody HistorySearchDto historySearchDto) {
       historySearchService.deleteHistory(historySearchDto);
       return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }


}
